import java.util.*;

public class Test {
    public static void main(String[] args) {
        TreeSet<String> set = new TreeSet<>();
        set.add("you");
        set.add("are");
        set.add("good");
        //set.add("good");

        //set.clear();

        Iterator<String> iterator = set.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next() + " ");
        }

        int ret = set.size();
        System.out.println(ret);

        Object[] objects = set.toArray();
        System.out.println(Arrays.toString(objects));

        TreeSet<String> set2 = new TreeSet<>();
        set2.add("you");
        set2.add("are");
        set2.add("good1");
        //boolean b = set.containsAll(set2);//判断set2中的元素在set中是否全部存在
        boolean b2 = set.addAll(set2);
        System.out.println(b2);

        System.out.println(set);
    }
    public static void main2(String[] args) {
        //底层是二叉搜索树，每次存放元素，都要进行大小比较，是key的值进行比较
        TreeMap<String,Integer> map = new TreeMap<>();
        //map.put(null,9);//err
        map.put("hello",4);
        //map.put("hello",6);
        map.put("you",3);
        map.put("are",2);

        Integer ret1 = map.get("hello");
        System.out.println(ret1);

        Integer ret2 = map.getOrDefault("me", -1);
        //Integer ret2 = map.getOrDefault("hello", -1);
        System.out.println(ret2);

        /*map.remove("hello");
        Integer ret3 = map.getOrDefault("hello", -1);
        System.out.println(ret3);*/

        Set<String> set = map.keySet();
        System.out.println(set);

        Collection<Integer> collection = map.values();
        System.out.println(collection);

        Set<Map.Entry<String,Integer>> entrySet = map.entrySet();
        for (Map.Entry<String,Integer> x: entrySet) {
            System.out.println("key:" + x.getKey() + "  value:" + x.getValue());
        }

        boolean ret3 = map.containsKey("yes");
        System.out.println(ret3);

        boolean ret4 = map.containsValue(4);
        System.out.println(ret4);

        System.out.println(map);
    }
    public static void main1(String[] args) {
        int[] array = {10,5,12,13,6};
        BinarySearchTree binarySearchTree = new BinarySearchTree();
        for (int x: array) {
            binarySearchTree.insert(x);
        }
    }
}
